package com.antis.olsl.magic.adapter;

import android.text.TextUtils;
import android.widget.TextView;

import com.antis.olsl.magic.R;
import com.antis.olsl.magic.response.GetTopAnalysisDetailResp;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.module.LoadMoreModule;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import java.util.List;

public class Top60DetailAdapter extends BaseQuickAdapter<GetTopAnalysisDetailResp.ContentBean, BaseViewHolder> implements LoadMoreModule {
    public Top60DetailAdapter(int layoutResId, List<GetTopAnalysisDetailResp.ContentBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, GetTopAnalysisDetailResp.ContentBean item) {
        if (!TextUtils.isEmpty(item.productCode)) {
            helper.setText(R.id.tv_1, item.productCode);
        }

        String productName = "";
        TextView tv2 = helper.getView(R.id.tv_2);
        if (!TextUtils.isEmpty(item.productName)) {
            if (item.productName.length() > 6) {
                productName = item.productName.substring(0, 6) + "...";
            } else {
                productName = item.productName;
            }
        }
        tv2.setSingleLine(true);
        tv2.setMaxLines(1);
        tv2.setEllipsize(TextUtils.TruncateAt.END);
        tv2.setText(productName);

        if (!TextUtils.isEmpty(item.attribute)) {
            helper.setText(R.id.tv_3, item.attribute);
        }

        if (!TextUtils.isEmpty(item.price)) {
            helper.setText(R.id.tv_4, item.price);
        }
    }
}
